package jps;

/**
 * A node in grid.
 *
 * @author Administrator
 *
 */
public class Node implements Comparable<Node> {

    /**
     * The x coordinate of the node on the grid.
     */
    private int x;
    /**
     * The y coordinate of the node on the grid.
     */
    private int y;
    /**
     * Whether this node can be walked through.
     */
    private boolean walkable = true;
    private int f;
    private int g;
    private int h;
    private boolean opened = false;
    private boolean closed = false;
    private Node parent;

    public Node(int x, int y) {
        this(x, y, true);
    }

    public Node(int x, int y, boolean walkable) {
        this.setX(x);
        this.setY(y);
        this.setWalkable(walkable);
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public boolean isWalkable() {
        return walkable;
    }

    public void setWalkable(boolean walkable) {
        this.walkable = walkable;
    }

    public int getG() {
        return g;
    }

    public void setG(int g) {
        this.g = g;
    }

    public int getF() {
        return f;
    }

    public void setF(int f) {
        this.f = f;
    }

    public boolean isOpened() {
        return opened;
    }

    public void setOpened(boolean opened) {
        this.opened = opened;
    }

    public boolean isClosed() {
        return closed;
    }

    public void setClosed(boolean closed) {
        this.closed = closed;
    }

    public Node getParent() {
        return parent;
    }

    public void setParent(Node parent) {
        this.parent = parent;
    }

    public int getH() {
        return h;
    }

    public void setH(int h) {
        this.h = h;
    }

    @Override
    public int compareTo(Node o) {

        return this.f - o.getF();
    }

    @Override
    public String toString() {
        return "x=" + x + " y=" + y + " walkable=" + walkable + " g=" + g + " f=" + f + " h=" + h + " opend=" + opened
                + " closed=" + closed;
    }

}

